import { checkDataOk } from "../response";

export class SystemController {
  constructor(opt) {
    this.proxyController = opt.proxyController;
    this.conf = opt.conf;
  }

  async getConfig(c){
    const res = await this.proxyController.request(c.req, '/public/system/config')

    const response = await res.json()

    if(! checkDataOk(response)){
      return c.json(response)
    }

    const config = response.data
    const oldOrgId = this.conf.get('org_id')

    const orgId = config.basic.can_reg_org === false ? 1 : config.basic.oem_org_id || 1

    if(orgId !== oldOrgId){
      this.conf.set('org_id', orgId)
    }

    return c.json(response)
  }
}